package Practicas.practica5;


import data.IntegerDataSetGenerator;

import impl.HeapOrderedSorter;
import impl.HeapSorter;
import test.BenchMark;

import java.util.ArrayList;
import java.util.Collections;

public class TestHeap {
    private ArrayList<Integer> list;
    private ArrayList<Integer> list2;

    private void testMiliTime(int valor) {
            list = new ArrayList<Integer>(valor);
            list2 = new ArrayList<Integer>(valor);
            IntegerDataSetGenerator integerDataSetGenerator = new IntegerDataSetGenerator();
            list = (ArrayList<Integer>) integerDataSetGenerator.createDescending(valor);
            Collections.shuffle(list);
            list2= (ArrayList<Integer>) list.clone();



        HeapOrderedSorter heapOrderedSorter = new HeapOrderedSorter();
        HeapSorter heapSorter = new HeapSorter();

        BenchMark benchMark = new BenchMark();

        heapOrderedSorter.addSorterListener(benchMark);
        heapSorter.addSorterListener(benchMark);

        float random;
        random = 0;

        long tiempoRan1, tiempoRan2;
        int swapsRamdon, comparationsRandom;
        String nameSorter = "";
        tiempoRan1 = tiempoRan2 = swapsRamdon = comparationsRandom = 0;
        for(int sort = 0 ; sort < 2 ; sort++){
            switch (sort) {
                case 0:
                    tiempoRan1 = System.currentTimeMillis();
                    heapSorter.sort(integerDataSetGenerator.getComparator(), list);
                    tiempoRan2 = System.currentTimeMillis();
                    random = tiempoRan2 - tiempoRan1;
                    swapsRamdon = benchMark.getnSwap();
                    comparationsRandom = benchMark.getComparations();
                    nameSorter = "HeapSorter";
                    break;
                case 1:
                    tiempoRan1 = System.currentTimeMillis();
                    heapOrderedSorter.sort(integerDataSetGenerator.getComparator(), list2);
                    tiempoRan2 = System.currentTimeMillis();
                    random = tiempoRan2 - tiempoRan1;
                    swapsRamdon = benchMark.getnSwap();
                    comparationsRandom = benchMark.getComparations();
                    nameSorter = "HeapOrderSorter";
                    break;
            }
            System.out.println("||  Cant: " + valor + "  ||  Tiempo " + random + "  ||" + "  ||  Comparaciones: " + comparationsRandom +
                    "  ||  swaps: " + swapsRamdon + " nombre: " + nameSorter);
            benchMark.resetAll();
        }
    }

    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        for (int i = 103; i < 107; i++) {
                testHeap.testMiliTime(i);

            System.out.println("*******************************");
            System.out.println("*******************************");
            System.out.println("*******************************");
        }

    }
}
